import json
import dbHandle

#对数据排序
def sort_data(cname, cdata):
    for i in range(1, len(cdata)):
        for j in range(0, len(cdata) - i):
            if cdata[j] < cdata[j + 1]:
                cdata[j], cdata[j + 1] = cdata[j + 1], cdata[j]
                cname[j], cname[j + 1] = cname[j + 1], cname[j]
    return cname, cdata


#分离key和value
def split_json(content, key):
    list_data = []
    list_name = []
    for single in content:
        list_name.append(single['name'])
        list_data.append(single['value'])
    list_name, list_data = sort_data(list_name, list_data)
    res_list = json.dumps({key: [list_name, list_data]}, ensure_ascii=False)
    return res_list


if __name__ == '__main__':
    res_list1 = []
    city_data = dbHandle.get_cityday('p')
    temp = json.loads(city_data[0])['pdata']
    #print(temp['confirm'])
    for key1 in temp:
        res_list1.append(split_json(temp[key1], key1))
    pass
